package com.sunny.ynhz.adapter;


import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sunny.ynhz.R;
import com.sunny.ynhz.bean.ProBean;
import com.sunny.ynhz.utils.TypeAndStatusUtil;

import java.util.List;

/**
 * Created by luao on 2017/7/20.
 */

public class ProblemDraftAdapter extends RecyclerView.Adapter<ProblemDraftAdapter.ViewHolder> {

    private List<ProBean> mData;

    public ProblemDraftAdapter(List<ProBean> data) {
        mData = data;
    }

    public interface OnItemClickListener {
        void onItemClick(View view, ProBean itemData, int position);
    }

    private OnItemClickListener mOnItemClickListener = null;

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_other_problem_draft, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(view);
        //将创建的View注册点击事件
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        final ProBean item = mData.get(position);

        holder.problemType.setText(TypeAndStatusUtil.getProblemTpye().get(item.getType()));
        holder.problemDetail.setText(item.getDescribe());
        holder.time.setText(item.getTime());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOnItemClickListener.onItemClick(view, item, position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public TextView problemType;
        public TextView problemDetail;
        public TextView time;


        public ViewHolder(View itemView) {
            super(itemView);
            problemType = itemView.findViewById(R.id.problem_type);
            problemDetail = itemView.findViewById(R.id.problem_detail);
            time = itemView.findViewById(R.id.time);

        }
    }
}
